package com.hmusic.mymusic.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 定位静态资源地址
 */
@Configuration
public class StaticConfig implements WebMvcConfigurer {

    @Value("${songPic.dir}")
    private String songPicPath;
    @Value("${song.dir}")
    private String songPath;
    @Value("${singerAvator.dir}")
    private String singerAvatorPath;
    @Value("${songListPic.dir}")
    private String songListPath;
    @Value("${avatorImages.dir}")
    private String userAvatorPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //歌手头像
        registry.addResourceHandler("/img/singerPic/**").addResourceLocations(
                "file:"+singerAvatorPath
        );
        //歌曲图片
        registry.addResourceHandler("/img/songPic/**").addResourceLocations(
                "file:"+songPicPath
        );
        //歌单图片
        registry.addResourceHandler("/img/songListPic/**").addResourceLocations(
                "file:"+songListPath
        );
        //歌曲地址
        registry.addResourceHandler("/song/**").addResourceLocations(
                "file:"+songPath
        );
        //用户头像地址
        registry.addResourceHandler("/img/avatorImages/**").addResourceLocations(
                "file:"+userAvatorPath
        );
    }
}
